

package com.springcloud.sc.ucpv5.client.commondata;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.springcloud.sc.ucpv5.client.application.message.DataMessageManager;
import com.springcloud.sc.ucpv5.client.commondata.data.SSInfoPara;
import com.springcloud.sc.ucpv5.client.commondata.data.SSInfoType;
import com.springcloud.sc.ucpv5.client.commondata.data.StatusStruct;
import com.springcloud.sc.ucpv5.client.commondata.data.User;
import com.springcloud.sc.ucpv5.client.commondata.data.UserInfo;
import com.springcloud.sc.ucpv5.client.commondata.data.UserLocal;
import com.springcloud.sc.ucpv5.client.contentmain.MainConstant;
import com.springcloud.sc.ucpv5.client.module.datamanager.BaseDataManager;
import com.springcloud.sc.ucpv5.client.module.media.TouchMediaConstant;
import com.springcloud.sc.ucpv5.client.resource.ResourceDataManager;
import com.springcloud.sc.ucpv5.client.util.DateTimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



public class MyUser extends ModelBase {
	
	private static final Logger logger = LoggerFactory.getLogger(MyUser.class);

	protected ArrayList<StatusStruct> statusList = new ArrayList<StatusStruct>();

	protected HashSet<String> statusHashSet = new HashSet<String>();

	protected User idlData;

	protected UserInfo userInfo;

	protected boolean isOnline = false;

	protected String physicsNodeNumber = "";

	public void setPhysicsNodeNumber(String physicsNodeNumber) {
		this.physicsNodeNumber = physicsNodeNumber;
	}

	public void setLogicNodeNumber(String logicNodeNumber) {
		this.logicNodeNumber = logicNodeNumber;
	}

	protected String logicNodeNumber = "";

	//
	protected int status = STATUS_UNKOWN;

	protected boolean isShowBlackIcon;

	// 通道子节点
	protected boolean isChannl = false;

	// 通道ID
	protected String channel = null;

	// 子节点描述
	protected String subDesc;

	// 子节点数目
	protected ArrayList<MyUser> children;

	public static String 视频终端挂靠用户号码标志 = "##";

	public MyUser(UserInfo userInfo, String physicsNodeNumber, String logicNodeNumber, int flag) {
		setUserInfo(userInfo);
		this.physicsNodeNumber = physicsNodeNumber;
		this.logicNodeNumber = logicNodeNumber;

		// 是否需要创造子通道号
		if (isSupportChannel()) {
			createChildren();
		}

		initStruct();
		BaseDataManager.getInstance().userAdd(this);
	}

	public MyUser(User idlData, String physicsNodeNumber, String logicNodeNumber, int flag) {
		setIdlData(idlData);
		this.physicsNodeNumber = physicsNodeNumber;
		this.logicNodeNumber = logicNodeNumber;

		// 是否需要创造子通道号
		if (isSupportChannel()) {
			createChildren();
		}
		initStruct();
		BaseDataManager.getInstance().userAdd(this);
	}

	public static MyUser createNewUserByTel(String tel) {
		User userIdl = new User();
		userIdl.UserTelno = tel;
		userIdl.UserName = tel;
		MyUser user = new MyUser(userIdl, "", "", 0);

		return user;
	}

	public MyUser(User idlData, String physicsNodeNumber, String logicNodeNumber, int flag, boolean isChannl) {

		this.isChannl = isChannl;

		setIdlData(idlData);
		this.physicsNodeNumber = physicsNodeNumber;
		this.logicNodeNumber = logicNodeNumber;

		initStruct();
	}

	private void initStruct() {

		//
		StatusStruct struct = new StatusStruct();
		struct.Number = getNumber();
		struct.status = MainConstant.Status_VLR_USER_STATUS_UNREACH;
		struct.PeerNumber = "";

		statusList.add(struct);
		statusHashSet.add(struct.PeerNumber + ":" + struct.status);
	}

	public boolean isDispather() {
		return getUserInfoData().getUserType() == 1;
	}

	public String getLabel() {
		if (this.isChannl) {
			return this.channel;
		}

		if (idlData.Desc != null && !"".equals(idlData.Desc)) {
			return idlData.Desc + "\n(" + idlData.UserTelno + ")";
		}
		return idlData.UserName + "\n(" + idlData.UserTelno + ")";
	}

	public boolean isOnline() {
		// 纯视频用户,且在上传, 则返回true
		if (isMediaUser() && isVideoUp()) {
			return true;
		}

		if (isOutUser()) {
			return true;
		}

		return isOnline;
	}

	/**
	 * 用户是否停机
	 * 
	 * @return
	 */
	public boolean isUserOffLine() {
		if (this.idlData.UserStatus == 4 || this.idlData.UserStatus == 5) {
			return true;
		}

		return false;
	}

	public int getPriority() {
		return idlData.Priority;
	}

	public String getUserName() {
		return idlData.UserName;
	}

	public String getKey() {
		if (isChannl) {
			// 带通道信息
			return idlData.UserTelno + "#" + channel;
		}

		return idlData.UserTelno;
	}

	public String getUserTelNo() {
		return idlData.UserTelno;
	}

	private String getStatusDesc() {
		if (statusList.size() > 1) {
			return MainConstant.ICON_EXT_USER_mulCalling;
		} else if (statusList.size() == 0) {
			return MainConstant.ICON_EXT_USER_offline;
		}

		if (isStatus(MainConstant.Status_VLR_USER_STATUS_IDLE)) {
			return MainConstant.ICON_EXT_USER_online;
		} else if (isStatus(MainConstant.Status_VLR_USER_STATUS_ALERTING)) {
			return MainConstant.ICON_EXT_USER_ring;
		} else if (isStatus(MainConstant.Status_VLR_USER_STATUS_LOGOUT) || isStatus(MainConstant.Status_VLR_USER_STATUS_UNREACH) || isStatus(MainConstant.Status_VLR_USER_STATUS_NOT_EXIST)) {
			return MainConstant.ICON_EXT_USER_offline;
		} else if (isStatus(MainConstant.Status_VLR_USER_STATUS_LISTENING)) {
			return MainConstant.ICON_EXT_USER_gListen;
		} else if (isStatus(MainConstant.Status_VLR_USER_STATUS_TALKING)) {
			return MainConstant.ICON_EXT_USER_gSpeak;
		} else if (isStatus(MainConstant.Status_VLR_USER_STATUS_TEL_BUSY)) {
			return MainConstant.ICON_EXT_USER_calling;
		} else if (isStatus(MainConstant.Status_GROUP_USER_STATUS_CALLING)) {
			return MainConstant.ICON_EXT_USER_calling;
		} else if (isStatus(MainConstant.Status_VLR_USER_STATUS_MONITORED)) {
			return MainConstant.ICON_EXT_USER_calling;
		} else if (isStatus(MainConstant.Status_VLR_USER_STATUS_MEDIAMEETING_ZHUXI)) {
			return MainConstant.ICON_EXT_USER_gSpeak;
		} else
			return MainConstant.ICON_EXT_USER_online;
	}

	public String getIconDesc() {

		String UserIconName = idlData.UserIconName;

		if ("".equals(UserIconName)) {
			if (isDispather()) {
				UserIconName = "O_User_0_online.png";
			} else {
				UserIconName = "O_User_1_online.png";
			}
		}
		String status = getStatusDesc();

		int index = UserIconName.lastIndexOf("_");
		return UserIconName.substring(0, index) + "_" + status + ".png";
	}

	public String getIconDesc(String status) {

		if (isChannl) {
			// 视频通道,固定显示
			MyUser user = BaseDataManager.getInstance().userGet(this.getNumber());

			if (user == null) {
				return "weizhi";
			}

			if (user.isOnline()) {
				return "Legend.object.Channel_0";
			} else {
				return "Legend.object.Channel_1";
			}
		}

		String UserIconName = idlData.UserIconName;

		if ("".equals(UserIconName)) {
			if (isDispather()) {
				UserIconName = "O_User_0_online.png";
			} else {
				UserIconName = "O_User_1_online.png";
			}
		}

		int index = UserIconName.lastIndexOf("_");

		// 判断是否纯视频用户
		if (isMediaUser()) {
			if (isVideoUp()) {
				status = MainConstant.ICON_EXT_USER_online;
			}
			if (!status.equals(MainConstant.ICON_EXT_USER_online)) {
				// 非在线,就是都不在线
				status = MainConstant.ICON_EXT_USER_offline;
			}
			return "Legend.type.CustomVideoHead." + UserIconName.substring(0, index) + "_" + status;
		}

		if (isOutUser()) {
			status = MainConstant.ICON_EXT_USER_online;
		}
		return "Legend.type.CustomUserHead." + UserIconName.substring(0, index) + "_" + status;
	}

	public boolean equals(Object tmp) {
		try {
			if (!(tmp instanceof MyUser)) {
				return false;
			}

			MyUser user = (MyUser) tmp;
			if (getKey().equals(user.getKey())) {
				if (true) {
					// 20131120 出现视频对话框打开多次,出现多个窗口,怀疑是这里因为, 用户只比较号码和子通道
					// 逻辑管理和物理节点数据,在做了重新查询上报时,强制做修正
					return true;
				}

				if (user.getLogicNodeNumber().equals(getLogicNodeNumber())) {
					return true;
				} else {
					if (user.getLogicNodeNumber().equals("")) {
						if (getLogicNodeNumber().equals(BaseDataManager.getInstance().getLoginNode().getLogic_NodeNumber())) {
							return true;
						}
					} else if (getLogicNodeNumber().equals("")) {
						if (user.getLogicNodeNumber().equals(BaseDataManager.getInstance().getLoginNode().getLogic_NodeNumber())) {
							return true;
						}
					}
					// StringBuffer buffer = new StringBuffer();
					// buffer.append("比较用户是否相等时,出现用户的逻辑节点不一致情况:");
					// buffer.append(user.getLogicNodeNumber());
					// buffer.append(" 和 ");
					// buffer.append(getLogicNodeNumber());
					// PublicUtil.debugInfo(buffer.toString());
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return false;
	}

	public int hashCode() {
		return this.getKey().hashCode() << 8;
	}

	public void invokeAction(int actionId) {
	}

	public boolean isStatus(int theStatus) {
		for (StatusStruct status : statusList) {
			try {
				if (theStatus == status.status)
					return true;
			} catch (Throwable e) {
			}
		}

		return false;
	}

	/**
	 * 判断用户是否空闲状态
	 * 
	 * @return
	 */
	public boolean isStatus_Free() {
		return isStatus(MainConstant.Status_VLR_USER_STATUS_IDLE);
	}

	/**
	 * 判断用户是否离线不可以状态
	 * 
	 * @return
	 */
	public boolean isStatus_OffLine() {
		if (statusList.size() == 0) {
			// 未知状态
			return true;
		}
		// 用户状态为关机, 不可达,不存在
		return isStatus(MainConstant.Status_VLR_USER_STATUS_LOGOUT) || isStatus(MainConstant.Status_VLR_USER_STATUS_UNREACH) || isStatus(MainConstant.Status_VLR_USER_STATUS_NOT_EXIST);
	}

	// public void setStatus(int status) {
	// this.status = status;
	// }

	public boolean setStatus(ArrayList<StatusStruct> list) {
		if (this.statusList.size() == list.size()) {
			int count = 0;
			for (StatusStruct stuct : list) {
				if (statusHashSet.contains(stuct.PeerNumber + ":" + stuct.status))
					count++;
			}
			if (count == list.size())
				return false;
		}
		this.statusList = list;

		statusHashSet.clear();
		isOnline = true;
		for (StatusStruct stuct : list) {
			if (stuct.status == MainConstant.Status_GROUP_USER_STATUS_NOT_EXIST || stuct.status == MainConstant.Status_GROUP_USER_STATUS_UNREACH
					|| stuct.status == MainConstant.Status_GROUP_USER_STATUS_LOGOUT) {
				isOnline = false;
			}
			statusHashSet.add(stuct.PeerNumber + ":" + stuct.status);
		}

		return true;

	}

	public String getStatusLabel() {
		StringBuffer buffer = new StringBuffer();

		String str = getStatusStr();
		if (str != null) {
			buffer.append("(");
			buffer.append(str);
			buffer.append(")");
		}
		//
		// String str_video = this.getVideoStauts();
		// if (str_video != null) {
		// if (str != null) {
		// buffer.append("\n");
		// }
		// buffer.append("(");
		// buffer.append(str_video);
		// buffer.append(")");
		// }
		return buffer.toString();
	}

	public static String getStatusDesc(StatusStruct tmpstatus) {
		try {
			int status = tmpstatus.status;
			String key = Integer.toHexString(status);
			if (key.length() < 2)
				key = "Status_GROUP_USER_STATUS_0X0" + key;
			else
				key = "Status_GROUP_USER_STATUS_0X" + key;
		} catch (Throwable e) {
		}

		return "";
	}

	public String getStatusStr() {
		if (statusList.size() > 0) {
			StringBuffer buf = new StringBuffer();
			for (StatusStruct tmpstatus : statusList) {
				if (buf.length() > 0) {
					buf.append("|");
				}
				buf.append(getStatusDesc(tmpstatus));
			}

			return buf.toString();
		} else {
			// 没有状态,本来是未知状态,现在定义为离线,图标置灰
			return "";
		}
	}

	public String getRemotePeerInfo(StatusStruct task_status) {
		String peerTel = task_status.PeerNumber;
		if ("".equals(peerTel.trim())) {
			return " ";
		} else {
			try {
				int status = task_status.status;
				MyGroup group = BaseDataManager.getInstance().groupGet(peerTel);
				if (group == null) {
					MyUser user = BaseDataManager.getInstance().userGetByTelNum(peerTel);
					if (user == null) {
						return peerTel;
					} else {
						return peerTel + "(" + user.getFieldText(MainConstant.FIELD_TYPE_NAME) + ")";
					}
				} else {
					return peerTel + "(" + group.getFieldText(MainConstant.FIELD_TYPE_NAME) + ")";
				}
				// if(status == DcsMainConstant.Status_VLR_USER_STATUS_LISTENING
				// || status == DcsMainConstant.Status_VLR_USER_STATUS_TALKING
				// || status ==
				// DcsMainConstant.Status_GROUP_USER_STATUS_CALLING){
				//
				//
				// DcsGroup group =
				// DcsBaseDataManager.getInstance().groupGet(peerTel);
				// if(group == null){
				// return peerTel;
				// }
				// else{
				// return
				// peerTel+"("+group.getFieldText(DcsMainConstant.FIELD_TYPE_NAME)+")";
				// }
				// }
				// else if(status ==
				// DcsMainConstant.Status_VLR_USER_STATUS_TEL_BUSY){
				// DcsUser user =
				// DcsBaseDataManager.getInstance().userGetByTelNum(peerTel);
				// if(user == null){
				// return peerTel;
				// }
				// else{
				// return
				// peerTel+"("+user.getFieldText(DcsMainConstant.FIELD_TYPE_NAME)
				// + ")";
				// }
				// }
				// else{
				// return peerTel;
				// }
			} catch (Throwable exp) {
				return peerTel;
			}
		}
	}

	public String getRemotePeerInfo() {
		if (statusList.size() > 0) {
			StringBuffer buf = new StringBuffer();
			for (StatusStruct task_status : statusList) {
				if (buf.length() > 0) {
					buf.append("|");
				}
				buf.append(getRemotePeerInfo(task_status));
			}

			return buf.toString();
		} else {
			return "";
		}
	}

	public String getTipLabel() {
		return getTipLabel(true);
	}

	public String getTipLabel(boolean showStatus) {
		StringBuffer buf = new StringBuffer();

		return buf.toString();
	}

	public String getFieldText(int fieldId) {
		switch (fieldId) {
		case MainConstant.FIELD_TYPE_NAME:
			if (idlData.Desc != null && !"".equals(idlData.Desc)) {
				return idlData.Desc;
			}
			return idlData.UserName;
		case MainConstant.FIELD_TYPE_TYPE:
			switch (this.userInfoData.设备类型值) {
			case 0:
				return "网络话机";
			case 1:
				return "调度台手柄";
			case 10:
				return "调度台";
			case 11:
				return "调度管理员";
			case 12:
				return "多组监听调度台";
			case 30:
				return "车载终端";
			case 31:
				return "手持终端";
			case 32:
				return "基地台";
			case 50:
				return "智能终端";
			case 60:
				return "摄像头用户";
			case 70:
				return "GPS设备";
			case 80:
				return "卡片机";
			case 90:
				return "无屏机设备";
			case 100:
				return "三防机";
			case 110:
				return "4G执法记录";
			case 120:
				return "无人机";
			default:
				return "" + this.userInfoData.设备类型值;

			}
		case MainConstant.FIELD_TYPE_Status:
			return getStatusStr() != null ? getStatusStr() : "";
		case MainConstant.FIELD_TYPE_ID:
			return idlData.UserTelno;
		case MainConstant.FIELD_TYPE_TEL:
		case MainConstant.FIELD_TYPE_DEFAULT_SEC_LABEL:
			return idlData.UserTelno;
			// case DcsMainConstant.FIELD_TYPE_AuthCallTelNo:
			// return idlData.;
		case MainConstant.FIELD_TYPE_Priority:
		case MainConstant.FIELD_TYPE_UserPriority:
			return "";
			// case DcsMainConstant.FIELD_TYPE_MGR_RIGHT:
			// return
			// DcsResourceDataManager.getInstance().getDcsStr(DcsDataBuffer.getInstance().hasRight(getValue(UID).toString())
			// ? "right.yes":"right.no" );
		case MainConstant.FIELD_TYPE_TALK_PEER_TEL: {
			return getRemotePeerInfo();
		}
		case MainConstant.FIELD_TYPE_IS_DISPATHER:
			return ResourceDataManager.getInstance().getDcsStr("admin".equals(idlData.UserName) ? "UserRole.System" : (isDispather() ? "UserRole.Dispather" : "UserRole.Normal"));

		}
		return "--";
	}

	public int getIdField(int fieldId) {
		return MainConstant.FIELD_TYPE_ID;
	}

	public String getSortLabel(int fieldId) {
		switch (fieldId) {
		case MainConstant.FIELD_TYPE_NAME:
		case MainConstant.FIELD_TYPE_ID:
		case MainConstant.FIELD_TYPE_TEL:
			if (fieldId == MainConstant.FIELD_TYPE_TEL) {
				fieldId = MainConstant.FIELD_TYPE_NAME;
			}
			return getFieldText(fieldId);
		default:
			return null;
		}
	}

	public String getSortKeyLabel() {
		return idlData.UserTelno;
	}

	public int getSortLevel() {
		int level = 3300;
		{
			if (this.isOnline()) {
				level = level - 300;
			}

			// 31=手持终端;30=车载终端;10=调度台;50=智能终端;11=调度管理员;0=网络话机;60=摄像头用户;80=卡片机
			if ("admin".equals(idlData.UserName)) {
				level = level + 10;
			} else if (isDispather()) {
				level = level + 11;
			} else if (isMediaUser()) {
				level = level + 100;
			} else if (idlData.UserType == 0) {
				level = level + 90;
			} else {
				level = level + getUserDevType();
			}
		}
		return level;
	}

	public int getLevel() {
		// TODO 自动生成方法存根
		return 0;
	}

	public String getTreeLabel() {
		StringBuffer buffer = new StringBuffer();

		return buffer.toString();
	}

	public boolean hasChildren() {
		if (this.children != null && this.children.size() > 0) {
			return true;
		}
		return this.isSupportChannel();
	}

	public void setLevel(int level) {

	}

	public User getIdlData() {
		return idlData;
	}

	public void setIdlData(User idlData) {
		User user_idl_old = this.idlData;
		this.idlData = idlData;

		// 检查视频类型是否改变
		checkChildChnage(user_idl_old, idlData);

		// 20111201 由于keep2字段作为组播类型字段, 在下发时,杜飞要求和用户类型合成一个字段,
		// 处理的地方 下发的有三个, 一个是增加,修改,和批增对话框, 查询的有两个, 分别是dcsuser 的 set idldata 和 set
		// userinfo
		userInfoData.userType_keep = idlData.UserType;

		try {
			int userType = idlData.UserType;

			userType = userType & 0x000000FF;

			userInfoData.userType = userType;
		} catch (Exception e) {
			// TODO: handle exception
		}

		// 20121106 由于上传的usertype 中包含了终端的车载,手持类型, 所以在此解出该值
		try {
			int tmp = (idlData.UserType >> 10) & 0x0000000F;
			userInfoData.设备类型值 = userInfoData.userType * 10 + tmp;

		} catch (Exception e) {
			// TODO: handle exception
		}

		try {
			int tmp = (idlData.UserType >> 8) & 0x00000001;
			userInfoData.机卡绑定 = tmp;
			;
		} catch (Exception e) {
			// TODO: handle exception
		}

	// wsy 20190514 用户其余信息都放置到iconname字段中, 同时考虑兼容处理
	try {
	    userInfoData.otherInfo = JSON.parseObject(idlData.UserIconName, MyUserInfoOtherData.class);
	} catch (Exception e) {
	    // TODO: handle exception
	}

	{
	    try {
		if (userInfoData.设备类型值 == ModelBaseConstant.用户类型.摄像头用户) {
		    if (userInfoData.otherInfo.appendNumber != null && !"".equals(userInfoData.otherInfo.appendNumber))
			;
		    setMeidaFatherUserDesc(userInfoData.otherInfo.appendNumber);
		}
	    } catch (Exception e) {
		// TODO: handle exception
	    }

	}
	// 缓存当前的用户idl信息
	userInfoData.user = this.idlData;
    }

	public String getPhysicsNodeNumber() {
		return physicsNodeNumber;
	}

	public UserInfo getUserInfo() {
		return getUserInfo(false);
	}

	public UserInfo getUserInfo(boolean async) {
		if (userInfo != null) {
			return userInfo;
		}

		if (async) {
			int result = DataMessageManager.getInstance().queryUserInfo_Async(getPhysicsNodeNumber(), getLogicNodeNumber(), this);

			return null;
		} else {
			SecuResult result = DataMessageManager.getInstance().queryUserInfo(getPhysicsNodeNumber(), getLogicNodeNumber(), this, false, false);
		}
		return userInfo;
	}

	// 20150701 处理用户详细信息, 主要是用在用户数据编辑处理上
	private MyUserInfoData userInfoData = new MyUserInfoData();

	// 20150701 增加用户额外详细信息的缓存类
	public MyUserInfoData getUserInfoData() {
		return this.userInfoData;
	}

	public MyUserInfoData getMyUserInfoData_copy() {
		MyUserInfoData userInfoData = getUserInfoData().clone();

		userInfoData.userInfo = getUserInfo_copy();
		return userInfoData;
	}

	public UserInfo getUserInfo_copy() {
		UserInfo info = new UserInfo();
		try {
			info.UserTelno = getUserInfo().UserTelno;
			info.UserName = getUserInfo().UserName;
			info.password = getUserInfo().password;
			info.UserType = getUserInfo().UserType;
			info.Priority = getUserInfo().Priority;
			info.UserStatus = getUserInfo().UserStatus;
			info.GrpList = getUserInfo().GrpList;
			info.PttPriority = getUserInfo().PttPriority;
			info.GroupPriority = getUserInfo().GroupPriority;
			info.Workplace = getUserInfo().Workplace;
			info.Address = getUserInfo().Address;
			info.Contact = getUserInfo().Contact;
			info.Desc = getUserInfo().Desc;
			info.addtime = getUserInfo().addtime;
			info.Odb = getUserInfo().Odb;

			info.AuthNodeIDList = getUserInfo().AuthNodeIDList;

			info.longitude = getUserInfo().longitude;
			info.latitude = getUserInfo().latitude;
			info.zoom = getUserInfo().zoom;
			info.UserIconName = getUserInfo().UserIconName;
			info.UserShowType = getUserInfo().UserShowType;
			info.UserMediaType = getUserInfo().UserMediaType;
			info.UserMediaID = getUserInfo().UserMediaID;
			info.utRegIp = getUserInfo().utRegIp;
			info.keep2 = getUserInfo().keep2;
			info.keep3 = getUserInfo().keep3;
			info.keep4 = getUserInfo().keep4;

			SSInfoType[] SSInfoTypelist = new SSInfoType[getUserInfo().SSInfoTypelist.length];
			for (int i = 0; i < getUserInfo().SSInfoTypelist.length; i++) {
				SSInfoType sSInfoType_keep = getUserInfo().SSInfoTypelist[i];

				SSInfoPara[] SSInfoParaList = new SSInfoPara[sSInfoType_keep.SSInfoParaList.length];

				for (int j = 0; j < sSInfoType_keep.SSInfoParaList.length; j++) {
					SSInfoPara sSInfoPara_keep = sSInfoType_keep.SSInfoParaList[j];

					SSInfoPara sSInfoPara_new = new SSInfoPara();
					sSInfoPara_new.name = sSInfoPara_keep.name;
					sSInfoPara_new.value = sSInfoPara_keep.value;
					SSInfoParaList[j] = sSInfoPara_new;
				}

				SSInfoType sSInfoType_new = new SSInfoType();
				sSInfoType_new.type = sSInfoType_keep.type;
				sSInfoType_new.open = sSInfoType_keep.open;
				sSInfoType_new.SSInfoParaList = SSInfoParaList;
				SSInfoTypelist[i] = sSInfoType_new;
			}
			info.SSInfoTypelist = SSInfoTypelist;

			UserLocal userLocal = new UserLocal();
			userLocal.ip = userLocal.ip;
			userLocal.port = userLocal.port;
			userLocal.status = userLocal.status;
			userLocal.type = userLocal.type;
			userLocal.currRegTime = userLocal.currRegTime;
			userLocal.prevRegTime = userLocal.prevRegTime;

			info.LocalInfo = userLocal;
		} catch (Exception e) {
			// TODO: handle exception
		}

		return info;

	}

	public UserInfo getUserInfo_NoQuery() {
		if (userInfo == null) {
			// 加入异步查询中
			// ExecutorServiceUtil.getInstance().addUserNum(getIdlData().UserTelno);
		}

		return userInfo;
	}

	// 20120423 记录保存的用户类型,在做编码前, 主要是为了修改时,能有原始值使用
	public int userType_keep;

	public void setUserInfo(UserInfo userInfo) {
		this.userInfo = userInfo;

		// 20111201 由于keep2字段作为组播类型字段, 在下发时,杜飞要求和用户类型合成一个字段,
		// 处理的地方 下发的有三个, 一个是增加,修改,和批增对话框, 查询的有两个, 分别是dcsuser 的 set idldata 和 set
		// userinfo
		try {
			userInfoData.userType_keep = userInfo.UserType;

			int userType = userInfo.UserType & 0x000000FF;

			int keep2 = (userInfo.UserType >> 9) & 0x00000001;

			userInfoData.userType = userType;

			// 保留
			userInfoData.组播类型 = String.valueOf(keep2);

			// 20121106 由于上传的usertype 中包含了终端的车载,手持类型, 所以在此解出该值
			try {
				int tmp = (userInfoData.userType_keep >> 10) & 0x0000000F;

				// 保留
				userInfoData.设备类型值 = userInfoData.userType * 10 + tmp;

			} catch (Exception e) {
				// TODO: handle exception
			}

			try {
				int tmp = (userInfo.UserType >> 8) & 0x00000001;
				userInfoData.机卡绑定 = tmp;
				;
			} catch (Exception e) {
				// TODO: handle exception
			}


	    // wsy 20190514 用户其余信息都放置到iconname字段中, 同时考虑兼容处理
	    try {
		userInfoData.otherInfo = JSON.parseObject(userInfo.UserIconName, MyUserInfoOtherData.class);
	    } catch (Exception e) {
		// TODO: handle exception
	    }

	    {
		try {
		    if (userInfoData.设备类型值 == ModelBaseConstant.用户类型.摄像头用户) {
			if (userInfoData.otherInfo.appendNumber != null && !"".equals(userInfoData.otherInfo.appendNumber))
			    ;
			setMeidaFatherUserDesc(userInfoData.otherInfo.appendNumber);
		    }
		} catch (Exception e) {
		    // TODO: handle exception
		}

	    }
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}

		if (userInfo != null) {
			User idlData = this.idlData == null ? new User() : this.idlData;

			// 保留媒体类型, 比较是否重建子用户
			User user_idl_old = new User();
			user_idl_old.UserMediaType = idlData.UserMediaType;
			user_idl_old.zoom = idlData.zoom;

			idlData.UserName = userInfo.UserName;
			idlData.UserTelno = userInfo.UserTelno;
			idlData.password = userInfo.password;
			idlData.UserType = userInfo.UserType;
			idlData.addtime = userInfo.addtime;
			idlData.Priority = userInfo.Priority;
			idlData.latitude = userInfo.latitude;
			idlData.longitude = userInfo.longitude;
			idlData.zoom = userInfo.zoom;
			idlData.GrpList = userInfo.GrpList;

			idlData.Desc = userInfo.Desc;
			idlData.UserIconName = userInfo.UserIconName;
			idlData.UserShowType = userInfo.UserShowType;
			idlData.UserMediaType = userInfo.UserMediaType;
			idlData.UserMediaID = userInfo.UserMediaID;

			// 检查视频类型是否改变
			// 检查视频类型是否改变
			this.idlData = idlData;
			checkChildChnage(user_idl_old, idlData);

			// 保留
			this.userInfoData.user = this.idlData;
			this.userInfoData.userInfo = this.userInfo;
		}
	}

	public String getLogicNodeNumber() {
		return logicNodeNumber;
	}

	public ArrayList<MyGroup> getGroupList() {
		String groups = this.userInfo == null ? this.idlData.GrpList : userInfo.GrpList;
		ArrayList<MyGroup> list = new ArrayList<MyGroup>();
		String[] groupList = groups.split("#");

		for (String groupNum : groupList) {
			MyGroup group = BaseDataManager.getInstance().groupGet(groupNum);
			if (group != null) {
				list.add(group);
			}
		}
		return list;
	}

	/**
	 * 收到消息,用户加入组或离开组时, 手工更改消息中组信息
	 * 
	 * @param groupTel
	 */
	public boolean dealToGroup(String groupTel, boolean isAdd) {
		String groups = this.userInfo == null ? this.idlData.GrpList : userInfo.GrpList;
	List<String> groupList = new ArrayList<String>();
	if (isAdd) {
	    {
		// 重新整理一下
		{
		    String[] tmps = groups.split("#");
		    for (String tmp : tmps) {
			if (!tmp.equals("") && !groupList.contains(tmp)) {
			    groupList.add(tmp);
			}
		    }
		}
		{
		    String[] tmps = groupTel.split("#");
		    for (String tmp : tmps) {
			if (!tmp.equals("") && !groupList.contains(tmp)) {
			    groupList.add(tmp);
			}
		    }
		}
	    }
	} else {
	    // 重新整理一下
	    {
		String[] tmps = groups.split("#");
		for (String tmp : tmps) {
		    if (!tmp.equals("") && !groupList.contains(tmp)) {
			groupList.add(tmp);
		    }
		}
	    }
	    {
		String[] tmps = groupTel.split("#");
		for (String tmp : tmps) {
		    if (!tmp.equals("") && groupList.contains(tmp)) {
			groupList.remove(tmp);
		    }
		}
	    }
	}

	StringBuilder builder = new StringBuilder();
	for (String tmp : groupList) {
	    builder.append(tmp);
	    builder.append("#");
	}
	groups = builder.toString();

	if (this.userInfo != null) {
	    this.userInfo.GrpList = groups;
	}

	this.idlData.GrpList = groups;
	return true;
	}

	// 视频状态
	public static final int STATUS_ONLINE = 0;
	public static final int STATUS_OFFLINE = 4;
	public static final int STATUS_UNKOWN = 8;
	public static final int STATUS_Viewing = 16;

	public static final int STATUS_Calling = 1;

	public static final int STATUS_VIDEO_UP = 32;

	public boolean isCalling() {
		return (status & STATUS_Calling) > 0;
	}

	public boolean isViewing() {
		return (status & STATUS_Viewing) > 0;
	}

	public void addStatusFalg(int status) {
		if (status == STATUS_Viewing) {
			this.status = status;
		} else if (status == STATUS_Calling) {
			if (!isCalling()) {
				this.status = STATUS_ONLINE;
			}

			this.status |= status;
		} else {
			this.status |= status;
		}
	}

	public void removeStatusFalg(int status) {
		if (status == STATUS_Viewing) {
			if (!isCalling()) {
				this.status = STATUS_ONLINE;
			} else {
				this.status = STATUS_Calling;
			}
		} else if (status == STATUS_Calling) {
			if (!isViewing()) {
				this.status = STATUS_ONLINE;
			} else {
				this.status = STATUS_Viewing;
			}
		} else if (status == STATUS_VIDEO_UP) {
			if (isVideoUp()) {
				this.status = STATUS_ONLINE;
			} else {
			}
		}
	}

	public String getVideoStauts() {
		// 是否终端用户
		if (isDispather()) {
			return null;
		}

		if (status == STATUS_UNKOWN) {
			return null;
		}

		return ResourceDataManager.getInstance().getDcsStr("DcsVideo.status." + status);
	}

	public boolean isVideoStatus_OFFLine() {
		return this.status == STATUS_OFFLINE;
	}

	public boolean isVideoStatus_Calling() {
		if ((this.status & STATUS_Calling) > 0) {
			return true;
		}
		return false;
	}

	public void refreshUserInfo() {
		SecuResult tempResult = DataMessageManager.getInstance().queryUserInfo(physicsNodeNumber, logicNodeNumber, this, false, false);
	}

	/**
	 * 判断用户是否支持视频
	 */
	public boolean isVideoExist() {
		return true;
	}

	/**
	 * 判断用户是否正在视频上传
	 */
	public boolean isVideoUp() {
		// 包含子通道,如果某个通道是视频上传状态,则显示为上传状态
		if (children != null && children.size() > 0) {
			for (MyUser child : children) {
				if (child.isVideoUp()) {
					return true;
				}
			}
			return false;
		}

		return (status & STATUS_VIDEO_UP) > 0;
	}

	public String getVideoGoid() {
		if (this.isChannl) {
			return this.getIdlData().UserTelno;
		}
		return this.getIdlData().UserTelno;
	}

	public String getDesc() {
		// TODO 自动生成方法存根
		if (idlData.Desc != null && !"".equals(idlData.Desc)) {
			return idlData.Desc + "(" + idlData.UserTelno + ")";
		}
		return idlData.UserName + "(" + idlData.UserTelno + ")";
	}

	public int getMediaType() {
		// 用户返回的视频类型固定为1 ,Mpeg4
		return getIdlData().UserMediaType;
		// return 1;
	}

	public String mediaServer = "";

	public String getMediaServer() {
		// TODO 自动生成方法存根
		return mediaServer;
	}

	public void setMediaServer(String mediaServer) {
		// TODO 自动生成方法存根
		this.mediaServer = mediaServer;
	}

	public String getLatitude() {
		// TODO 自动生成方法存根
		return idlData.latitude;
	}

	public String getLongitude() {
		// TODO 自动生成方法存根
		return idlData.longitude;
	}

	public String getZoom() {
		// TODO 自动生成方法存根
		return idlData.zoom;
	}

	public String getNumber() {
		// TODO 自动生成方法存根
		return idlData.UserTelno;
	}

	public String getChannel() {
		// TODO 自动生成方法存根
		// 新疆返回新版调度台如果调用第一路是, 采用 号码#1 会出现打开不了视频现象, 这里做了适配
		// 但最终会用 号码#1 进行打开视频
		// if(idlData.UserMediaType == 摄象头类型_默认摄像头 && "1".equals(this.channel)){
		// return null;
		// }

		return this.channel;
	}

	/**
	 * 取得用户的联系方式
	 * 
	 * @return
	 */
	public String getContactInfo() {
		StringBuffer buffer = new StringBuffer();
		buffer.append(" 姓名:");
		buffer.append(this.getUserInfo().Workplace);
		buffer.append(" 岗位:");
		buffer.append(this.getUserInfo().Address);
		buffer.append(" 联系方式:");
		buffer.append(this.getUserInfo().Contact);

		return buffer.toString();
	}

	public void createChildren() {
		if (children == null) {
			children = new ArrayList();
		} else {
			children.clear();

			// 即使有
			children = new ArrayList();
		}

		// 通道数
		int channel_num = Integer.valueOf(idlData.zoom);

		if (idlData.UserMediaType == TouchMediaConstant.摄像头类型.摄象头类型_默认摄像头) {
			if (channel_num <= 0) {
				return;
			}

			if (channel_num == 11) {
				channel_num = 5;
			}

			if (channel_num == 12) {
				// 先增加内置
				MyUser video = new MyUser(idlData, physicsNodeNumber, logicNodeNumber, 0, true);
				video.setParent(this);
				video.setChannel(5 + "");
				children.add(video);

				channel_num = 5;
			} else if (channel_num == 13) {
				// 先增加内置, 还有一路外置
				MyUser video = new MyUser(idlData, physicsNodeNumber, logicNodeNumber, 0, true);
				video.setParent(this);
				video.setChannel(5 + "");
				children.add(video);

				MyUser video_2 = new MyUser(idlData, physicsNodeNumber, logicNodeNumber, 0, true);
				video_2.setParent(this);
				video_2.setChannel(1 + "");
				children.add(video_2);

				channel_num = 0;
			}
		}

		if (is子用户通道从1开始(this)) {
			// 海康从1号通道开始
			for (int i = 1; i <= channel_num; i++) {
				MyUser video = new MyUser(idlData, physicsNodeNumber, logicNodeNumber, 0, true);
				video.setParent(this);
				video.setChannel(i + "");

				children.add(video);
			}
		} else if (idlData.UserMediaType == TouchMediaConstant.摄像头类型.摄象头类型_单兵直连) {
			createChildren_单兵();
		} else {
			// 构建n个通道对象
			// 1号通道暂时不可用
			for (int i = 0; i < channel_num; i++) {
				MyUser video = new MyUser(idlData, physicsNodeNumber, logicNodeNumber, 0, true);
				video.setParent(this);
				video.setChannel(i + "");

				children.add(video);
			}
		}
	}

	public void childAdd(MyUser child) {
		if (children == null) {
			children = new ArrayList<MyUser>();
		}
		children.add(child);
	}

	public static boolean is子用户通道从1开始(MyUser user) {
		if (user.getIdlData().UserMediaType == TouchMediaConstant.摄像头类型.摄象头类型_海康_NPE摄像头 || user.getIdlData().UserMediaType == TouchMediaConstant.摄像头类型.摄象头类型_中泰通) {
			return true;
		} else {
			return false;
		}
	}

	public ArrayList getChildren() {
		if (children == null) {
			children = new ArrayList();
		}

		return children;
	}

	public void setChildren(ArrayList children) {
		if (children == null) {
			children = new ArrayList();
		}
		this.children = children;
	}

	public void setChannel(String channel) {
		this.channel = channel;
	}

	public MyUser getChildren(String channel) {
		if (this.children == null || this.children.size() <= 0) {
			return this;
		}

		for (Object user : this.children) {
			MyUser t = (MyUser) user;
			if (t.channel.equals(channel)) {
				return t;
			}
		}

		return null;
	}

	public String toString() {
		return getDesc();
	}

	/**
	 * 是否属于通道
	 */
	public boolean isChannel() {
		return isChannl;
	}

	private boolean checkChildChnage(User userInfo_old, User userInfo) {
		if (userInfo_old == null) {
			return false;
		}
		if (userInfo_old != null) {
			// 查看媒体类型是否改变
			if (userInfo_old.UserMediaType == userInfo.UserMediaType) {
				// 查看通道数目是否改变
				if (userInfo_old.zoom.equals(userInfo.zoom)) {
					return false;
				}
			}
		}

		// 检查视频类型是否改变
		if (children == null) {
			children = new ArrayList();
		} else {
			children.clear();

			// 即使有
			children = new ArrayList();
		}

		// 需要重新建立子节点了
		// 是否需要创造子通道号
		if (isSupportChannel()) {
			createChildren();
		}

		return true;
	}

	/**
	 * 是否支持子通道
	 * 
	 * @return
	 */
	public boolean isSupportChannel() {
		if (idlData.UserMediaType != TouchMediaConstant.摄像头类型.摄象头类型_默认摄像头 && idlData.UserMediaType != TouchMediaConstant.摄像头类型.摄象头类型_锐明 && idlData.UserMediaType != TouchMediaConstant.摄像头类型.摄象头类型_创世
				&& idlData.UserMediaType != TouchMediaConstant.摄像头类型.摄象头类型_海康_NPE摄像头 && idlData.UserMediaType != TouchMediaConstant.摄像头类型.摄象头类型_海康摄像头
				&& idlData.UserMediaType != TouchMediaConstant.摄像头类型.摄象头类型_中泰通 && idlData.UserMediaType != TouchMediaConstant.摄像头类型.摄象头类型_大华
				&& idlData.UserMediaType != TouchMediaConstant.摄像头类型.摄象头类型_大华_车载 && idlData.UserMediaType != TouchMediaConstant.摄像头类型.摄象头类型_单兵直连
				&& idlData.UserMediaType != TouchMediaConstant.摄像头类型.摄象头类型_紫荆 && idlData.UserMediaType != TouchMediaConstant.摄像头类型.摄象头类型_思拓) {
			return false;
		}

		if (isChannl) {
			return false;
		}

		int channel_num = 0;
		try {
			channel_num = Integer.valueOf(idlData.zoom);
		} catch (Exception e) {
			return false;
		}

		if (channel_num <= 0) {
			return false;
		}

		return true;
	}

	/**
	 * 判断用户是否空闲状态
	 * 
	 * @return
	 */
	public boolean isMediaMeetingUser_ZhuXi() {
		return isStatus(MainConstant.Status_VLR_USER_STATUS_MEDIAMEETING_ZHUXI);
	}

	/**
	 * 判断用户是否低电状态状态
	 * 
	 * @return
	 */
	// 新增用户低电状态 2016/12/5
	public boolean isLowPower = false; // 用户低电状态

	public boolean isLowPowerUser() {
		if (!isOnline()) {
			return false;
		}
		return isLowPower;
	}

	public void setLowPower(boolean flag) {
		if (!isOnline()) {
			isLowPower = false;
		}
		isLowPower = flag;
	}

	//
	// //记录车辆是车载终端或手持终端类型, 在返回User 或 UserInfo Idl中获取
	// private int userDevType = -1;
	//
	// public int getUserDevType(){
	// return userDevType;
	// }
	//
	// // 记录用户开户时间, 方便在修改用户时,重新填入
	// private String addtime;
	// public String getAddTime(){
	// if(addtime == null){
	// System.out.println("出现异常MyUser getAddTime addtime == null:" );
	// addtime = "";
	// }
	// return addtime;
	// }
	// private String Contact;
	// public String getContact(){
	// if(Contact == null){
	// System.out.println("出现异常MyUser getContact Contact == null:");
	// Contact = "";
	// }
	// return Contact;
	// }
	//
	// private String Workplace;
	// public String getWorkplace(){
	// if(Workplace == null){
	// System.out.println("出现异常MyUser getContact Contact == null:");
	// Workplace = "";
	// }
	// return Workplace;
	// }

	/**
	 * 是否纯视频用户
	 * 
	 * @return
	 */
	public boolean isMediaUser() {
		return this.userInfoData.设备类型值 == 60;
	}

	/**
	 * 是否Gps用户
	 * 
	 * @return
	 */
	public boolean isGpsUser() {
		return this.userInfoData.设备类型值 == 70;
	}

	/**
	 * 是否外网用户
	 * 
	 * @return
	 */
	public boolean isOutUser() {
	return this.userInfoData.设备类型值 == 1 || this.userInfoData.设备类型值 == 2;
	}

	public boolean is单兵直连() {
		if (idlData.UserMediaType == TouchMediaConstant.摄像头类型.摄象头类型_单兵直连) {
			if (isChannl) {
				return false;
			}
			return true;
		}
		return false;
	}

	public void 单兵直连用户刷新() {
		// 判断是否已经连接过
		if (nIndex > 0) {
			return;
		}

		getUserInfo();
	}

	public void setMeidaFatherUserDesc(String userMeidaFatherUserDesc) {
		if (userMeidaFatherUserDesc == null) {
			return;
		} else {
			if (isMediaFatherUser) {
				// 已经挂靠成功
				return;
			}
		}
		// 将用户挂靠到父用户中
		MyUser userParent = BaseDataManager.getInstance().userGetByTelNum(userMeidaFatherUserDesc);
		if (userParent == null) {
			// 查询用户详细
			User tmp = new User();
			tmp.UserName = userMeidaFatherUserDesc;
			tmp.UserTelno = userMeidaFatherUserDesc;
			MyUser user_ = new MyUser(tmp, this.physicsNodeNumber, this.logicNodeNumber, 0);
			// 出发查询客户自生详细信息(如果已存在,则不触发查询)
			SecuResult result = DataMessageManager.getInstance().queryUserInfo(this.physicsNodeNumber, this.logicNodeNumber, user_, false, false);
			if (result.getRetCode() == 0) {
				userParent = BaseDataManager.getInstance().userGetByTelNum(userMeidaFatherUserDesc);
			} else {
				logger.info("挂靠号码在系统内不存在:" + userMeidaFatherUserDesc);
			}
		}
		if (userParent != null) {
	    userParent.getListModel().addUser(this);
		}
	}

	/**
	 * 从挂靠用户内把用户删除
	 */
	public void setMeidaFatherUserDesc_rmv() {
	if (this.userInfoData.otherInfo.appendNumber == null) {
			return;
		} else {
			if (!isMediaFatherUser) {
				// 已经挂靠成功
				return;
			}
		}
	MyUser userParent = BaseDataManager.getInstance().userGetByTelNum(this.userInfoData.otherInfo.appendNumber);
		if (userParent != null) {
			ArrayList<MyUser> childeren = userParent.getChildren();
			// 判断是否存在
			if (childeren.contains(this)) {
				childeren.remove(this);
			}
		}
	}

	// 是否指定了父类用户
	boolean isMediaFatherUser = false;

	public boolean isMediaFatherUser() {
		return isMediaFatherUser;
	}

	public int nIndex = -1; // 链接Index
	public String goupName = "";
	public int goupIndex = -1;

	public String CamName = "";
	public int CamIndex = -1;
	public int CamIndex_status = -1;

	public int CamIndex_chanel_status = -1;

	public void createChildren_单兵() {
		getUserInfo();
		// if(Media_4_zhengzhoudanbing_dll.connectToServer(this)){
		// Media_4_zhengzhoudanbing_dll.createChildren_group(this);
		// }
	}

	// 20140811 增加判断gps是否在上传中, 上传的显示用户在线
	private boolean isGpsUp = false;
	private long gpsTime = 0;
//	private MapDataInfo mapDataInfo = new MapDataInfo();

	public long getGpsTime() {
		return gpsTime;
	}

	public void setGpsTime(long gpsTime) {
		this.gpsTime = gpsTime;
	}

//	public MapDataInfo getMapDataInfo() {
//		return mapDataInfo;
//	}

//	public void setMapDataInfo(MapDataInfo mapDataInfo) {
//		this.mapDataInfo = mapDataInfo;
//	}

	public boolean isGpsUp() {
		if (isGpsUp) {
			if (Math.abs(DateTimeUtil.getCurTime_Long() / 1000 - gpsTime) > 300) {
				return false;
			}
		}
		return isGpsUp;
	}

	public void setGpsUp(boolean isGpsUp) {
		this.isGpsUp = isGpsUp;
	}

	/*private List<MapWarmDataInfo> warmInfos = null;

	public List<MapWarmDataInfo> getWarmInfos() {
		return warmInfos;
	}*/

	public int getUserDevType() {
		return this.userInfoData.设备类型值;
	}

/*	public MapWarmDataInfo getWarmInfoByfenceid(int fenceid) {
		if (warmInfos != null) {
			for (MapWarmDataInfo data : warmInfos) {
				if (data.getFenceId() == fenceid) {
					return data;
				}
			}
		}
		return null;
	}

	public void setWarmInfos(List<MapWarmDataInfo> warmInfos) {
		this.warmInfos = warmInfos;
	}*/


	public int[] getSupportField() {
		// TODO Auto-generated method stub
		return null;
	}


	public String[] getFieldNames() {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * 判断用户是否具有该组的语音发布权限
	 * @param groupNumber
	 * @return
	 */
	public boolean checkVoiceAuthorityGroup(String groupNumber) {
		try {
			if (userInfoData.otherInfo.voiceAuthorityGroupList.contains(groupNumber)) {
				return true;
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		return false;
	}
}
